import java.util.Arrays;

public class MajorityElement {
    public static void main(String[] args) {

        int[] a = { 2, 2, 1, 1, 1, 2, 2 };
        System.out.println(majorityElement(a));
    }

    public static int majorityElement(int[] a) {
        int amount = 0;
        int i = 0;

        for (i = 0; i < a.length; i++) {
            if (i != 0 && a[i] == a[i - 1]) {
                continue;
            }

            for (int j = i; j < a.length; j++) {
                if (a[i] == a[j]) {
                    amount++;
                }
            }

            if (amount >= a.length / 2) {
                break;
            } else {
                amount = 0;
            }
        }

        return a[i];
    }
}
